import requests

class TpshopLogin():
    session=None
    @classmethod
    def __get_vifity(cls):
        if cls.session is None:
            url_v="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify"
            cls.session=requests.Session()
            cls.session.get(url_v)
    @classmethod
    def tplogin(cls,formData):
        # session为空则获取令牌,非空则继续用session发请求
        cls.__get_vifity()
        url_login="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        res=cls.session.post(url_login,data=formData)
        cls.__free_session()
        return res
    @classmethod
    def __free_session(cls):
        if cls.session:
            cls.session.close()
            cls.session=None



